﻿using UnityEngine;
using System.Collections;

public class Shark : MonoBehaviour {
	public GameObject target;
	public float speed;
	Collider[] hitColliders;
	public Texture2D[] textures;
	// Use this for initialization
	void Start () {
	//	Debug.Log("im a shae]rk");
	}
	
	// Update is called once per frame
	void Update () {
		if(Spawner.startSpawning){
		transform.position = Vector3.MoveTowards(transform.position, target.transform.position, speed*Time.deltaTime);
		}
		Collider[] hitColliders = Physics.OverlapSphere(transform.position,8);

		foreach(Collider hit in hitColliders){
			if(hit.gameObject.tag == "pufferfish"){
				//Debug.Log("wtffff!!");
				transform.renderer.material.mainTexture = textures[1];
			}else{
				transform.renderer.material.mainTexture = textures[0];
			}

		}
	}
	void OnTriggerEnter(Collider other){

		if(other.gameObject.tag == "pufferfish"){
		//	Debug.Log("oejaigrbhteg");
			//Destroy(other.gameObject);

		}
	}
	void OnCollisionEnter(Collision other){
		
		if(other.gameObject.tag == "pufferfish"){
			//	Debug.Log("oejaigrbhteg");
		//	Destroy(other.gameObject);
			
		}
	}
}
